package feedback

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"
	"gitee.com/liuxuezhan/ar-platform/admin-api/pkg/code"
	"gitee.com/liuxuezhan/ar-platform/base-common/auth"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/setting/client/feedback"
	"github.com/zeromicro/go-zero/core/logc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddFeedbackLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 新增意见反馈
func NewAddFeedbackLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddFeedbackLogic {
	return &AddFeedbackLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AddFeedbackLogic) AddFeedback(req *types.AddFeedbackReq) (resp *types.Empty, err error) {

	u, err := l.svcCtx.SettingService.Feedback.AddFeedback(l.ctx, &feedback.AddFeedbackReq{UserId: auth.GetTokenUid(l.ctx), MerchantId: 1, Content: req.Content})

	if err != nil {
		logc.Error(l.ctx, "AddFeedback err:", err)
		return nil, err
	}

	if u.Code != int64(code.SettingRpcSuccessful.Code()) {
		return nil, code.BusinessFailure
	}
	resp = &types.Empty{}
	return
}
